<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="/bootstrap.css">
    <style>
        .container {
            width: 500px;
            margin: 20px auto;
        }

        .add {
            width: 100%;
            height: 40px;
            font-size: 35px;
            text-align: center;
            line-height: 40px;

        }

        body {
            background: #ccc;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <template id="txt">
        <div class="container">
            <div class="add">信息添加</div>
            <p class="form-group">
                <label for="username">username:</label>
                <input type="text" v-model="users.username" class="form-control">
            </p>
            <p class="form-group">
                <label for="age">age:</label>
                <input type="text" v-model="users.age" class="form-control">
            </p>
            <p class="form-group">
                <input type="radio" v-model="users.sex" value="boy">boy
                <input type="radio" v-model="users.sex" value="girl">girl
            </p>
            <p class="form-group">
                <label for="phone">phone:</label>
                <input type="text" v-model="users.phone" class="form-control">
            </p>
            <p class="form-group">
                <input type="button" value="save" @click="save()" class="btn btn-success">
                <a href="/vue.html">返回</a>
            </p>
        </div>
    </template>
</body>
<script src="/vue.min.js"></script>
<script src="/jquery.min.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        template: '#txt',
        data: function () {
            return {
                users:{
                    username:'',
                    age:'',
                    sex:'',
                    phone:''
                }
            }
        },
        methods: {
            save:function(){
                $.post('/users/add',this.users).done(function(){
                    location.href='/vue.html'
                })
            }
        }
    })
</script>

</html>